package com.lun.blog.repostory;

import com.lun.blog.pojo.Blog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface BlogRepository extends JpaRepository<Blog,Long> , JpaSpecificationExecutor<Blog> {



    @Query(value = "select* from t_blog tb where published='1' order by create_time desc limit 0,1 ",nativeQuery = true)
    Blog findBlog();

    @Query(value = "select count(tb.id) as countBlog,tt.id as typeId,tt.name as typeName from t_blog tb,t_type tt \n" +
            "where tt.id = tb.type_id \n" +
            "group by type_id ",nativeQuery = true)
    List<Map> findCountByTypeId();


    long count();

    @Query(value = "select sum(view) from t_blog",nativeQuery = true)
    long sumByView();

}
